package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.bussiness.domain.SysBusinessDynamic;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bussiness.domain.SysBusinessDept;
import com.ruoyi.bussiness.service.ISysBusinessDeptService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 机构Controller
 *
 * @author ruoyi
 * @date 2023-12-18
 */
@RestController
@RequestMapping("/bussiness/dept")
public class SysBusinessDeptController extends BaseController
{
    @Autowired
    private ISysBusinessDeptService sysBusinessDeptService;

    /**
     * 查询机构列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:dept:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBusinessDept sysBusinessDept)
    {
        startPage();
        List<SysBusinessDept> list = sysBusinessDeptService.selectSysBusinessDeptList(sysBusinessDept);
        return getDataTable(list);
    }

    /**
     * 导出机构列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:dept:export')")
    @Log(title = "机构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBusinessDept sysBusinessDept)
    {
        List<SysBusinessDept> list = sysBusinessDeptService.selectSysBusinessDeptList(sysBusinessDept);
        ExcelUtil<SysBusinessDept> util = new ExcelUtil<SysBusinessDept>(SysBusinessDept.class);
        util.exportExcel(response, list, "机构数据");
    }

    /**
     * 获取机构详细信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:dept:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return success(sysBusinessDeptService.selectSysBusinessDeptByDeptId(deptId));
    }

    /**
     * 新增机构
     */
    @PreAuthorize("@ss.hasPermi('bussiness:dept:add')")
    @Log(title = "机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBusinessDept sysBusinessDept)
    {
        return toAjax(sysBusinessDeptService.insertSysBusinessDept(sysBusinessDept));
    }

    /**
     * 修改机构
     */
    @PreAuthorize("@ss.hasPermi('bussiness:dept:edit')")
    @Log(title = "机构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBusinessDept sysBusinessDept)
    {
        return toAjax(sysBusinessDeptService.updateSysBusinessDept(sysBusinessDept));
    }

    /**
     * 删除机构
     */
    @PreAuthorize("@ss.hasPermi('bussiness:dept:remove')")
    @Log(title = "机构", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(sysBusinessDeptService.deleteSysBusinessDeptByDeptIds(deptIds));
    }

    @PutMapping("/moveUpOrDown")
    public AjaxResult moveUpOrDown(@RequestBody SysBusinessDept entity)
    {
        return sysBusinessDeptService.moveUpOrDown(entity);
    }

}
